import { defineStore } from 'pinia'

export const useStateStore = defineStore('state', {
  state: () => ({
    //加载 true/false
    loadingGlobal: false,

    //平台名称
    platformName: `川海SaaS管理服务平台`,
    //平台logo地址
    platformLogo: require('@/assets/imgs/logo.png'),

    //客服电话
    servicePhone: '',
    //客服名称
    serviceName: '',

    //鉴权信息
    platformHeadType: 'rcmsPlatform',
    Authorization: JSON.parse(window.localStorage.getItem('USER_AUTHOR')) || {
      Authorization: `'','','',3,20,''`,
    },

    //未读消息数
    msgnoReadForm: {},
    //消息自动刷新间隔 ms
    msgRefreshTime: 300000,

    //可见菜单id集合
    menuIds: [],

    onOffLineMenu: null,

    onOffOptions: [
      {
        value: 'all',
        label: '全部导航',
      },
      {
        value: 'on',
        label: '只看线上导航',
      },
      {
        value: 'off',
        label: '只看线下导航',
      },
    ],

    // 订单状态翻译
    orderStatusForm: {
      1: '待支付',
      2: '已支付',
      3: '已受理',
      4: '部分成功-进行中',
      5: '成功',
      6: '关闭',
      7: '失败',
      8: '部分成功-已完成',
    },

    //退款状态翻译
    refundStatusForm: {
      0: '无退款',
      100: '退款已申请',
      200: '已退款',
      300: '拒绝退款',
      400: '退款失败',
    },

    //激活状态翻译
    activeStatusForm: {
      0: '未激活',
      10: '已下单',
      12: '激活中',
      14: '下单失败',
      20: '已激活',
      22: '激活且充值',
      30: '激活失败',
    },

    //最新步骤翻译
    latestPhaseForm: {
      100: '订单创建成功',
      110: '初审失败',
      200: '分销订单已扣费',
      220: '分销订单欠费未支付',
      300: '审核通过',
      310: '审核失败，开户人证件信息异常',
      400: '选号成功',
      410: '选号失败',
      500: '上游下单成功',
      510: '上游下单准备',
      520: '上游下单失败',
      590: '等待人工生产',
      1000: '订单关闭',
    },

    //提现状态
    txStatus: {
      1: '发起提现',
      2: '已关闭',
      3: '提现失败',
      4: '提现成功',
      5: '待审核',
      6: '待发放',
    },

    //排序字段翻译
    orderByData: {
      leftFee: "b.left_fee",
      chargeTotal: "b.charge_total",
      usedTotal: "b.used_total",
      incomeRest: "c.income_rest",
      incomeTotal: "c.income_total",
      incomeWithdraw: "c.income_withdraw",
      incomeFreezen: "c.income_freezen",
    },
  }),
  getters: {
    getLoadingGlobal: (state) => {
      return state.loadingGlobal
    },
    getPlatformName: (state) => {
      return state.platformName
    },
    getPlatformLogo: (state) => {
      return state.platformLogo
    },
    getOrderStatusForm: (state) => {
      return state.orderStatusForm
    },
    getRefundStatusForm: (state) => {
      return state.refundStatusForm
    },
    getActiveStatusForm: (state) => {
      return state.activeStatusForm
    },
    getLatestPhaseForm: (state) => {
      return state.latestPhaseForm
    },
    getPlatformHeadType: (state) => {
      return state.platformHeadType
    },
    getAuthorization: (state) => {
      return state.Authorization.Authorization
    },
    getMsgnoReadForm: (state) => {
      return state.msgnoReadForm
    },
    getMsgRefreshTime: (state) => {
      return state.msgRefreshTime
    },
    getMenuIds: (state) => {
      return state.menuIds
    },
    getServicePhone: (state) => {
      return state.servicePhone
    },
    getServiceName: (state) => {
      return state.serviceName
    },
    getOnOffLineMenu: (state) => {
      return state.onOffLineMenu
    },
    getOnOffOptions: (state) => {
      return state.onOffOptions
    },
    getTxStatus: (state) => {
      return state.txStatus
    },
    getOrderByData: (state) => {
      return state.orderByData
    }
  },
  actions: {
    setLoadingGlobal(is) {
      this.loadingGlobal = is
    },
    setLoadingGlobal(name) {
      this.platformName = name
    },
    setPlatformLogo(url) {
      this.platformLogo = url
    },
    setOrderStatusForm(form) {
      this.orderStatusForm = form
    },
    setRefundStatusForm(form) {
      this.refundStatusForm = form
    },
    setActiveStatusForm(form) {
      this.activeStatusForm = form
    },
    setLatestPhaseForm(form) {
      this.latestPhaseForm = form
    },
    setPlatformHeadType(type) {
      this.platformHeadType = type
    },
    setAuthorization(Authorization) {
      this.Authorization = Authorization
    },
    setMsgnoReadForm(form) {
      this.msgnoReadForm = form
    },
    setMsgRefreshTime(time) {
      this.msgRefreshTime = time
    },
    setMenuIds(list) {
      this.menuIds = list
    },
    setOnOffLineMenu(onOffLineMenu) {
      this.onOffLineMenu = onOffLineMenu
    },
  },
})
